home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / mpload / mpcnv.c next >
Text File  |  1991-10-18  |  3KB  |  135 lines

  1. /*
  2.  *    Mac-Paint to TIFF Image File converter
  3.  *
  4.  *        1988/05/08 Waku Factory
  5.  *        1991/01/25 
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. #define PIXWIDTH 576
  12. #define PIXHEIGHT 720
  13.  
  14. /*
  15.     TIFF format definition
  16. */
  17.  
  18. /* structure of IFD field */
  19. typedef struct {
  20.     short tag ;
  21.     short type ;
  22.     long  count ;
  23.     long  value ;
  24. } IFD_E ;
  25.  
  26.  
  27. struct {
  28.     long ver ;
  29.     long ifdofs ;
  30.     short ifds ;
  31.     IFD_E tag[15] ;
  32.     long ifde ;
  33.     char dum[0x1f0-0xc2] ;
  34.     long xa,xb,ya,yb ;
  35. } head = { 0x2a4949, 8, 15,
  36.     0xFE,  4, 1, 0,
  37.     0x100, 3, 1, PIXWIDTH,
  38.     0x101, 3, 1, PIXHEIGHT,
  39.     0x102, 3, 1, 1,
  40.     0x103, 3, 1, 1, 
  41.     0x106, 3, 1, 0,
  42.     0x10a, 3, 1, 1,
  43.     0x111, 4, 1, 0x200,
  44.     0x115, 3, 1, 1, 
  45.     0x116, 4, 1, PIXWIDTH,
  46.     0x117, 4, 1, PIXWIDTH/8*PIXHEIGHT,
  47.     0x119, 2, 1, 1, 
  48.     0x11a, 5, 1, 0x1f0,
  49.     0x11b, 5, 1, 0x1f8,
  50.     0x11c, 3, 1, 1,
  51.     0 } ;
  52.  
  53. char lbuf[ PIXWIDTH / 8 ] ;
  54. int headsize ;
  55.  
  56. main( ac,av )
  57. int ac ;
  58. char **av ;
  59. {
  60.     char name[256] ;
  61.     FILE *sfp, *dfp ;
  62.     int x,l,cnt,ch ;
  63.     headsize = 512+128 ;
  64.     cnt = 1 ;
  65.     if( *av[1] == '-' && *(av[1]+1) == 'r' ) {
  66.         headsize = 512 ;
  67.         cnt = 2 ;
  68.     }
  69.     if( ac < cnt+1  ) usage() ;
  70.     strcpy( name, av[cnt] ) ;
  71.     strcat( name, ".MP" ) ;
  72.     if( ( sfp = fopen( name, "rb" )) == NULL )
  73.         error( "Source File Can't Open" ) ;
  74.     printf( "Open source file : %s\n", name ) ;
  75.     
  76.     strcpy( name, av[cnt] ) ;
  77.     strcat( name, ".TIF" ) ;
  78.     if( ( dfp = fopen( name, "wb" )) == NULL )
  79.         error( "Writ file Can't Open") ;
  80.     printf( "Open  dest. file : %s\n", name ) ;
  81.  
  82.      head.xa = head.ya = 75 ;
  83.      head.xb = head.yb = 1 ;
  84.  
  85.      fwrite( &head, sizeof( head ) , 1, dfp ) ;
  86.     fseek( sfp, headsize, SEEK_SET ) ;
  87.     printf( "Converting...." ) ;
  88.     
  89.     for( l = 0 ; l < PIXHEIGHT ; l++ ) {
  90.         x = cnt = 0 ;
  91.         while( (ch = getc( sfp )) != EOF ) {
  92.             ch &= 0xFF ;
  93.             if( cnt-- == 0 )
  94.                 if( ch < 72 ) {
  95.                     cnt = ch + 1 ;
  96.                 }
  97.                 else {
  98.                     cnt = 257 - ch ;
  99.                     ch = getc( sfp ) ^ 0xFF ;
  100.                     while( cnt-- > 0 ) {
  101.                         lbuf[x++] = ch ^ 0xFF ;
  102.                         if( x == 72 ) goto exit ;
  103.                     }
  104.                     cnt = 0 ;
  105.                 }
  106.             else {
  107.                 lbuf[x++] = ch  ;
  108.                 if( x == 72 ) goto exit ;
  109.             }
  110.         }
  111.     exit:    fwrite( lbuf, sizeof(lbuf), 1, dfp ) ;
  112.     }
  113.     fclose( sfp ) ;
  114.     fclose( dfp ) ;
  115.     printf( "compreted!\n" ) ;
  116. }
  117.  
  118. usage()
  119. {
  120.     printf( "MacPaint format to TIFF file converter\n" ) ;
  121.     printf( "  USAGE : run386 mpcnv <filename>\n" ) ;
  122.     printf( "          couvert <filename>.MP to <filename>.TIF\n" ) ;
  123.     printf( "              Thus, <filename> must have no extension.\n" ) ;
  124.     exit( 0 ) ;
  125. }
  126.  
  127. error( mes )
  128. char *mes ;
  129. {
  130.     printf( "******* %s Error\n", mes ) ;
  131.     exit( 1 ) ;
  132. }
  133.  
  134.  
  135.